package com.ioudi.digu.flex.message;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.ioudi.digu.flex.message.destination.MessageDestination;

import flex.messaging.Destination;
import flex.messaging.FlexContext;
import flex.messaging.messages.CommandMessage;
import flex.messaging.messages.Message;

public class MessageService extends flex.messaging.services.MessageService
{
	private ApplicationContext ac;
	 
	private ApplicationContext getAppContext()
	{
		if(ac == null)
		{
			ac = WebApplicationContextUtils.getWebApplicationContext(FlexContext.getServletContext());
		}
		return ac;
	}
	
	public Destination createDestination(String id)
    {
        MessageDestination destination = new MessageDestination();
        destination.setId(id);
        destination.setManaged(isManaged());
        destination.setService(this);
        return destination;
    }
	
    public Object serviceMessage(Message message)
    {
    	//TODO save the message as sender
    	return super.serviceMessage(message);
    }
    
    public Object serviceCommand(CommandMessage message)
    { 	
    	Object result = super.serviceCommand(message);
    	return result;
    }

}
